home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2010 April / PCA177.iso / ESSENTIALS / Firefox Setup.exe / nonlocalized / chrome / browser.jar / content / browser / preferences / advanced.js < prev    next >
Encoding:
Text File  |  2009-07-15  |  21.3 KB  |  580 lines

  1. //@line 39 "e:\builds\moz2_slave\win32_build\build\browser\components\preferences\advanced.js"
  2.  
  3. // Load DownloadUtils module for convertByteUnits
  4. Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
  5.  
  6. var gAdvancedPane = {
  7.   _inited: false,
  8.  
  9.   /**
  10.    * Brings the appropriate tab to the front and initializes various bits of UI.
  11.    */
  12.   init: function ()
  13.   {
  14.     this._inited = true;
  15.     var advancedPrefs = document.getElementById("advancedPrefs");
  16.  
  17.     var extraArgs = window.arguments[1];
  18.     if (extraArgs && extraArgs["advancedTab"]){
  19.       advancedPrefs.selectedTab = document.getElementById(extraArgs["advancedTab"]);
  20.     } else {
  21.       var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
  22.       if (preference.value === null)
  23.         return;
  24.       advancedPrefs.selectedIndex = preference.value;
  25.     }
  26.  
  27. //@line 65 "e:\builds\moz2_slave\win32_build\build\browser\components\preferences\advanced.js"
  28.     this.updateAppUpdateItems();
  29.     this.updateAutoItems();
  30.     this.updateModeItems();
  31. //@line 69 "e:\builds\moz2_slave\win32_build\build\browser\components\preferences\advanced.js"
  32.     this.updateOfflineApps();
  33.   },
  34.  
  35.   /**
  36.    * Stores the identity of the current tab in preferences so that the selected
  37.    * tab can be persisted between openings of the preferences window.
  38.    */
  39.   tabSelectionChanged: function ()
  40.   {
  41.     if (!this._inited)
  42.       return;
  43.     var advancedPrefs = document.getElementById("advancedPrefs");
  44.     var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
  45.     preference.valueFromPreferences = advancedPrefs.selectedIndex;
  46.   },
  47.   
  48.   // GENERAL TAB
  49.  
  50.   /*
  51.    * Preferences:
  52.    *
  53.    * accessibility.browsewithcaret
  54.    * - true enables keyboard navigation and selection within web pages using a
  55.    *   visible caret, false uses normal keyboard navigation with no caret
  56.    * accessibility.typeaheadfind
  57.    * - when set to true, typing outside text areas and input boxes will
  58.    *   automatically start searching for what's typed within the current
  59.    *   document; when set to false, no search action happens
  60.    * general.autoScroll
  61.    * - when set to true, clicking the scroll wheel on the mouse activates a
  62.    *   mouse mode where moving the mouse down scrolls the document downward with
  63.    *   speed correlated with the distance of the cursor from the original
  64.    *   position at which the click occurred (and likewise with movement upward);
  65.    *   if false, this behavior is disabled
  66.    * general.smoothScroll
  67.    * - set to true to enable finer page scrolling than line-by-line on page-up,
  68.    *   page-down, and other such page movements
  69.    * layout.spellcheckDefault
  70.    * - an integer:
  71.    *     0  disables spellchecking
  72.    *     1  enables spellchecking, but only for multiline text fields
  73.    *     2  enables spellchecking for all text fields
  74.    */
  75.  
  76.   /**
  77.    * Stores the original value of the spellchecking preference to enable proper
  78.    * restoration if unchanged (since we're mapping a tristate onto a checkbox).
  79.    */
  80.   _storedSpellCheck: 0,
  81.  
  82.   /**
  83.    * Returns true if any spellchecking is enabled and false otherwise, caching
  84.    * the current value to enable proper pref restoration if the checkbox is
  85.    * never changed.
  86.    */
  87.   readCheckSpelling: function ()
  88.   {
  89.     var pref = document.getElementById("layout.spellcheckDefault");
  90.     this._storedSpellCheck = pref.value;
  91.  
  92.     return (pref.value != 0);
  93.   },
  94.  
  95.   /**
  96.    * Returns the value of the spellchecking preference represented by UI,
  97.    * preserving the preference's "hidden" value if the preference is
  98.    * unchanged and represents a value not strictly allowed in UI.
  99.    */
  100.   writeCheckSpelling: function ()
  101.   {
  102.     var checkbox = document.getElementById("checkSpelling");
  103.     return checkbox.checked ? (this._storedSpellCheck == 2 ? 2 : 1) : 0;
  104.   },
  105.  
  106.   // NETWORK TAB
  107.  
  108.   /*
  109.    * Preferences:
  110.    *
  111.    * browser.cache.disk.capacity
  112.    * - the size of the browser cache in KB
  113.    */
  114.  
  115.   /**
  116.    * Displays a dialog in which proxy settings may be changed.
  117.    */
  118.   showConnections: function ()
  119.   {
  120.     document.documentElement.openSubDialog("chrome://browser/content/preferences/connection.xul",
  121.                                            "", null);
  122.   },
  123.  
  124.   /**
  125.    * Converts the cache size from units of KB to units of MB and returns that
  126.    * value.
  127.    */
  128.   readCacheSize: function ()
  129.   {
  130.     var preference = document.getElementById("browser.cache.disk.capacity");
  131.     return preference.value / 1024;
  132.   },
  133.  
  134.   /**
  135.    * Converts the cache size as specified in UI (in MB) to KB and returns that
  136.    * value.
  137.    */
  138.   writeCacheSize: function ()
  139.   {
  140.     var cacheSize = document.getElementById("cacheSize");
  141.     var intValue = parseInt(cacheSize.value, 10);
  142.     return isNaN(intValue) ? 0 : intValue * 1024;
  143.   },
  144.  
  145.   /**
  146.    * Clears the cache.
  147.    */
  148.   clearCache: function ()
  149.   {
  150.     var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
  151.                                     .getService(Components.interfaces.nsICacheService);
  152.     try {
  153.       cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
  154.     } catch(ex) {}
  155.   },
  156.  
  157.   readOfflineNotify: function()
  158.   {
  159.     var pref = document.getElementById("browser.offline-apps.notify");
  160.     var button = document.getElementById("offlineNotifyExceptions");
  161.     button.disabled = !pref.value;
  162.     return pref.value;
  163.   },
  164.  
  165.   showOfflineExceptions: function()
  166.   {
  167.     var bundlePreferences = document.getElementById("bundlePreferences");
  168.     var params = { blockVisible     : false,
  169.                    sessionVisible   : false,
  170.                    allowVisible     : false,
  171.                    prefilledHost    : "",
  172.                    permissionType   : "offline-app",
  173.                    manageCapability : Components.interfaces.nsIPermissionManager.DENY_ACTION,
  174.                    windowTitle      : bundlePreferences.getString("offlinepermissionstitle"),
  175.                    introText        : bundlePreferences.getString("offlinepermissionstext") };
  176.     document.documentElement.openWindow("Browser:Permissions",
  177.                                         "chrome://browser/content/preferences/permissions.xul",
  178.                                         "", params);
  179.   },
  180.  
  181.   // XXX: duplicated in browser.js
  182.   _getOfflineAppUsage: function (host, groups)
  183.   {
  184.     var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
  185.                        getService(Components.interfaces.nsIApplicationCacheService);
  186.     if (!groups) {
  187.       groups = cacheService.getGroups({});
  188.     }
  189.     var ios = Components.classes["@mozilla.org/network/io-service;1"].
  190.               getService(Components.interfaces.nsIIOService);
  191.  
  192.     var usage = 0;
  193.     for (var i = 0; i < groups.length; i++) {
  194.       var uri = ios.newURI(groups[i], null, null);
  195.       if (uri.asciiHost == host) {
  196.         var cache = cacheService.getActiveCache(groups[i]);
  197.         usage += cache.usage;
  198.       }
  199.     }
  200.  
  201.     var storageManager = Components.classes["@mozilla.org/dom/storagemanager;1"].
  202.                          getService(Components.interfaces.nsIDOMStorageManager);
  203.     usage += storageManager.getUsage(host);
  204.  
  205.     return usage;
  206.   },
  207.  
  208.   /**
  209.    * Updates the list of offline applications
  210.    */
  211.   updateOfflineApps: function ()
  212.   {
  213.     var pm = Components.classes["@mozilla.org/permissionmanager;1"]
  214.                        .getService(Components.interfaces.nsIPermissionManager);
  215.  
  216.     var list = document.getElementById("offlineAppsList");
  217.     while (list.firstChild) {
  218.       list.removeChild(list.firstChild);
  219.     }
  220.  
  221.     var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
  222.                        getService(Components.interfaces.nsIApplicationCacheService);
  223.     var groups = cacheService.getGroups({});
  224.  
  225.     var bundle = document.getElementById("bundlePreferences");
  226.  
  227.     var enumerator = pm.enumerator;
  228.     while (enumerator.hasMoreElements()) {
  229.       var perm = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
  230.       if (perm.type == "offline-app" &&
  231.           perm.capability != Components.interfaces.nsIPermissionManager.DEFAULT_ACTION &&
  232.           perm.capability != Components.interfaces.nsIPermissionManager.DENY_ACTION) {
  233.         var row = document.createElement("listitem");
  234.         row.id = "";
  235.         row.className = "offlineapp";
  236.         row.setAttribute("host", perm.host);
  237.         var converted = DownloadUtils.
  238.                         convertByteUnits(this._getOfflineAppUsage(perm.host, groups));
  239.         row.setAttribute("usage",
  240.                          bundle.getFormattedString("offlineAppUsage",
  241.                                                    converted));
  242.         list.appendChild(row);
  243.       }
  244.     }
  245.   },
  246.  
  247.   offlineAppSelected: function()
  248.   {
  249.     var removeButton = document.getElementById("offlineAppsListRemove");
  250.     var list = document.getElementById("offlineAppsList");
  251.     if (list.selectedItem) {
  252.       removeButton.setAttribute("disabled", "false");
  253.     } else {
  254.       removeButton.setAttribute("disabled", "true");
  255.     }
  256.   },
  257.  
  258.   removeOfflineApp: function()
  259.   {
  260.     var list = document.getElementById("offlineAppsList");
  261.     var item = list.selectedItem;
  262.     var host = item.getAttribute("host");
  263.  
  264.     var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  265.                             .getService(Components.interfaces.nsIPromptService);
  266.     var flags = prompts.BUTTON_TITLE_IS_STRING * prompts.BUTTON_POS_0 +
  267.                 prompts.BUTTON_TITLE_CANCEL * prompts.BUTTON_POS_1;
  268.  
  269.     var bundle = document.getElementById("bundlePreferences");
  270.     var title = bundle.getString("offlineAppRemoveTitle");
  271.     var prompt = bundle.getFormattedString("offlineAppRemovePrompt", [host]);
  272.     var confirm = bundle.getString("offlineAppRemoveConfirm");
  273.     var result = prompts.confirmEx(window, title, prompt, flags, confirm,
  274.                                    null, null, null, {});
  275.     if (result != 0)
  276.       return;
  277.  
  278.     // clear offline cache entries
  279.     var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
  280.                        getService(Components.interfaces.nsIApplicationCacheService);
  281.     var ios = Components.classes["@mozilla.org/network/io-service;1"].
  282.               getService(Components.interfaces.nsIIOService);
  283.     var groups = cacheService.getGroups({});
  284.     for (var i = 0; i < groups.length; i++) {
  285.         var uri = ios.newURI(groups[i], null, null);
  286.         if (uri.asciiHost == host) {
  287.             var cache = cacheService.getActiveCache(groups[i]);
  288.             cache.discard();
  289.         }
  290.     }
  291.  
  292.     // send out an offline-app-removed signal.  The nsDOMStorage
  293.     // service will clear DOM storage for this host.
  294.     var obs = Components.classes["@mozilla.org/observer-service;1"]
  295.                         .getService(Components.interfaces.nsIObserverService);
  296.     obs.notifyObservers(null, "offline-app-removed", host);
  297.  
  298.     // remove the permission
  299.     var pm = Components.classes["@mozilla.org/permissionmanager;1"]
  300.                        .getService(Components.interfaces.nsIPermissionManager);
  301.     pm.remove(host, "offline-app",
  302.               Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
  303.     pm.remove(host, "offline-app",
  304.               Components.interfaces.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
  305.  
  306.     list.removeChild(item);
  307.     gAdvancedPane.offlineAppSelected();
  308.   },
  309.  
  310.   // UPDATE TAB
  311.  
  312.   /*
  313.    * Preferences:
  314.    *
  315.    * app.update.enabled
  316.    * - true if updates to the application are enabled, false otherwise
  317.    * extensions.update.enabled
  318.    * - true if updates to extensions and themes are enabled, false otherwise
  319.    * browser.search.update
  320.    * - true if updates to search engines are enabled, false otherwise
  321.    * app.update.auto
  322.    * - true if updates should be automatically downloaded and installed,
  323.    *   possibly with a warning if incompatible extensions are installed (see
  324.    *   app.update.mode); false if the user should be asked what he wants to do
  325.    *   when an update is available
  326.    * app.update.mode
  327.    * - an integer:
  328.    *     0    do not warn if an update will disable extensions or themes
  329.    *     1    warn if an update will disable extensions or themes
  330.    *     2    warn if an update will disable extensions or themes *or* if the
  331.    *          update is a major update
  332.    */
  333.  
  334.   /**
  335.    * Enables and disables various UI preferences as necessary to reflect locked,
  336.    * disabled, and checked/unchecked states.
  337.    *
  338.    * UI state matrix for update preference conditions
  339.    * 
  340.    * UI Components:                                     Preferences
  341.    * 1 = Firefox checkbox                               i   = app.update.enabled
  342.    * 2 = When updates for Firefox are found label       ii  = app.update.auto
  343.    * 3 = Automatic Radiogroup (Ask vs. Automatically)   iii = app.update.mode
  344.    * 4 = Warn before disabling extensions checkbox
  345.    * 
  346.    * States:
  347.    * Element     p   val     locked    Disabled 
  348.    * 1           i   t/f     f         false
  349.    *             i   t/f     t         true
  350.    *             ii  t/f     t/f       false
  351.    *             iii 0/1/2   t/f       false
  352.    * 2,3         i   t       t/f       false
  353.    *             i   f       t/f       true
  354.    *             ii  t/f     f         false
  355.    *             ii  t/f     t         true
  356.    *             iii 0/1/2   t/f       false
  357.    * 4           i   t       t/f       false
  358.    *             i   f       t/f       true
  359.    *             ii  t       t/f       false
  360.    *             ii  f       t/f       true
  361.    *             iii 0/1/2   f         false
  362.    *             iii 0/1/2   t         true   
  363.    * 
  364.    */
  365. //@line 403 "e:\builds\moz2_slave\win32_build\build\browser\components\preferences\advanced.js"
  366.   updateAppUpdateItems: function () 
  367.   {
  368.     var aus = 
  369.         Components.classes["@mozilla.org/updates/update-service;1"].
  370.         getService(Components.interfaces.nsIApplicationUpdateService);
  371.  
  372.     var enabledPref = document.getElementById("app.update.enabled");
  373.     var enableAppUpdate = document.getElementById("enableAppUpdate");
  374.  
  375.     enableAppUpdate.disabled = !aus.canUpdate || enabledPref.locked;
  376.   },
  377.  
  378.   /**
  379.    * Enables/disables UI for "when updates are found" based on the values,
  380.    * and "locked" states of associated preferences.
  381.    */
  382.   updateAutoItems: function () 
  383.   {
  384.     var enabledPref = document.getElementById("app.update.enabled");
  385.     var autoPref = document.getElementById("app.update.auto");
  386.     
  387.     var updateModeLabel = document.getElementById("updateModeLabel");
  388.     var updateMode = document.getElementById("updateMode");
  389.     
  390.     var disable = enabledPref.locked || !enabledPref.value ||
  391.                   autoPref.locked;
  392.     updateModeLabel.disabled = updateMode.disabled = disable;
  393.   },
  394.  
  395.   /**
  396.    * Enables/disables the "warn if incompatible extensions/themes exist" UI
  397.    * based on the values and "locked" states of various preferences.
  398.    */
  399.   updateModeItems: function () 
  400.   {
  401.     var enabledPref = document.getElementById("app.update.enabled");
  402.     var autoPref = document.getElementById("app.update.auto");
  403.     var modePref = document.getElementById("app.update.mode");
  404.     
  405.     var warnIncompatible = document.getElementById("warnIncompatible");
  406.     
  407.     var disable = enabledPref.locked || !enabledPref.value || autoPref.locked ||
  408.                   !autoPref.value || modePref.locked;
  409.     warnIncompatible.disabled = disable;
  410.   },
  411.  
  412.   /**
  413.    * Stores the value of the app.update.mode preference, which is a tristate
  414.    * integer preference.  We store the value here so that we can properly
  415.    * restore the preference value if the UI reflecting the preference value
  416.    * is in a state which can represent either of two integer values (as
  417.    * opposed to only one possible value in the other UI state).
  418.    */
  419.   _modePreference: -1,
  420.  
  421.   /**
  422.    * Reads the app.update.mode preference and converts its value into a
  423.    * true/false value for use in determining whether the "Warn me if this will
  424.    * disable extensions or themes" checkbox is checked.  We also save the value
  425.    * of the preference so that the preference value can be properly restored if
  426.    * the user's preferences cannot adequately be expressed by a single checkbox.
  427.    *
  428.    * app.update.modee         Checkbox State    Meaning
  429.    * 0                        Unchecked         Do not warn
  430.    * 1                        Checked           Warn if there are incompatibilities
  431.    * 2                        Checked           Warn if there are incompatibilities,
  432.    *                                            or the update is major.
  433.    */
  434.   readAddonWarn: function ()
  435.   {
  436.     var preference = document.getElementById("app.update.mode");
  437.     var doNotWarn = preference.value != 0;
  438.     gAdvancedPane._modePreference = doNotWarn ? preference.value : 1;
  439.     return doNotWarn;
  440.   },
  441.  
  442.   /**
  443.    * Converts the state of the "Warn me if this will disable extensions or
  444.    * themes" checkbox into the integer preference which represents it,
  445.    * returning that value.
  446.    */
  447.   writeAddonWarn: function ()
  448.   {
  449.     var warnIncompatible = document.getElementById("warnIncompatible");
  450.     return !warnIncompatible.checked ? 0 : gAdvancedPane._modePreference;
  451.   },
  452.  
  453.   /**
  454.    * Displays the history of installed updates.
  455.    */
  456.   showUpdates: function ()
  457.   {
  458.     var prompter = Components.classes["@mozilla.org/updates/update-prompt;1"]
  459.                              .createInstance(Components.interfaces.nsIUpdatePrompt);
  460.     prompter.showUpdateHistory(window);
  461.   },
  462. //@line 500 "e:\builds\moz2_slave\win32_build\build\browser\components\preferences\advanced.js"
  463.  
  464.   /**
  465.    * The Extensions checkbox and button are disabled only if the enable Addon
  466.    * update preference is locked. 
  467.    */
  468.   updateAddonUpdateUI: function ()
  469.   {
  470.     var enabledPref = document.getElementById("extensions.update.enabled");
  471.     var enableAddonUpdate = document.getElementById("enableAddonUpdate");
  472.  
  473.     enableAddonUpdate.disabled = enabledPref.locked;
  474.   },  
  475.   
  476.   // ENCRYPTION TAB
  477.  
  478.   /*
  479.    * Preferences:
  480.    *
  481.    * security.enable_ssl3
  482.    * - true if SSL 3 encryption is enabled, false otherwise
  483.    * security.enable_tls
  484.    * - true if TLS encryption is enabled, false otherwise
  485.    * security.default_personal_cert
  486.    * - a string:
  487.    *     "Select Automatically"   select a certificate automatically when a site
  488.    *                              requests one
  489.    *     "Ask Every Time"         present a dialog to the user so he can select
  490.    *                              the certificate to use on a site which
  491.    *                              requests one
  492.    */
  493.  
  494.   /**
  495.    * Displays the user's certificates and associated options.
  496.    */
  497.   showCertificates: function ()
  498.   {
  499.     document.documentElement.openWindow("mozilla:certmanager",
  500.                                         "chrome://pippki/content/certManager.xul",
  501.                                         "", null);
  502.   },
  503.  
  504.   /**
  505.    * Displays a dialog which describes the user's CRLs.
  506.    */
  507.   showCRLs: function ()
  508.   {
  509.     document.documentElement.openWindow("mozilla:crlmanager", 
  510.                                         "chrome://pippki/content/crlManager.xul",
  511.                                         "", null);
  512.   },
  513.  
  514.   /**
  515.    * Displays a dialog in which OCSP preferences can be configured.
  516.    */
  517.   showOCSP: function ()
  518.   {
  519.     document.documentElement.openSubDialog("chrome://mozapps/content/preferences/ocsp.xul",
  520.                                            "", null);
  521.   },
  522.  
  523.   /**
  524.    * Displays a dialog from which the user can manage his security devices.
  525.    */
  526.   showSecurityDevices: function ()
  527.   {
  528.     document.documentElement.openWindow("mozilla:devicemanager",
  529.                                         "chrome://pippki/content/device_manager.xul",
  530.                                         "", null);
  531.   }
  532. //@line 570 "e:\builds\moz2_slave\win32_build\build\browser\components\preferences\advanced.js"
  533.   ,
  534.  
  535.   // SYSTEM DEFAULTS
  536.  
  537.   /*
  538.    * Preferences:
  539.    *
  540.    * browser.shell.checkDefault
  541.    * - true if a default-browser check (and prompt to make it so if necessary)
  542.    *   occurs at startup, false otherwise
  543.    */
  544.  
  545.   /**
  546.    * Checks whether the browser is currently registered with the operating
  547.    * system as the default browser.  If the browser is not currently the
  548.    * default browser, the user is given the option of making it the default;
  549.    * otherwise, the user is informed that this browser already is the browser.
  550.    */
  551.   checkNow: function ()
  552.   {
  553.     var shellSvc = Components.classes["@mozilla.org/browser/shell-service;1"]
  554.                              .getService(Components.interfaces.nsIShellService);
  555.     var brandBundle = document.getElementById("bundleBrand");
  556.     var shellBundle = document.getElementById("bundleShell");
  557.     var brandShortName = brandBundle.getString("brandShortName");
  558.     var promptTitle = shellBundle.getString("setDefaultBrowserTitle");
  559.     var promptMessage;
  560.     const IPS = Components.interfaces.nsIPromptService;
  561.     var psvc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  562.                          .getService(IPS);
  563.     if (!shellSvc.isDefaultBrowser(false)) {
  564.       promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage", 
  565.                                                      [brandShortName]);
  566.       var rv = psvc.confirmEx(window, promptTitle, promptMessage, 
  567.                               IPS.STD_YES_NO_BUTTONS,
  568.                               null, null, null, null, { });
  569.       if (rv == 0)
  570.         shellSvc.setDefaultBrowser(true, false);
  571.     }
  572.     else {
  573.       promptMessage = shellBundle.getFormattedString("alreadyDefaultBrowser",
  574.                                                      [brandShortName]);
  575.       psvc.alert(window, promptTitle, promptMessage);
  576.     }
  577.   }
  578. //@line 616 "e:\builds\moz2_slave\win32_build\build\browser\components\preferences\advanced.js"
  579. };
  580.